home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / util / shell / ShellScr.lha / ShellScr / src / paths.asm < prev    next >
Encoding:
Assembly Source File  |  1998-04-10  |  4.7 KB  |  231 lines

  1. ; For copying DOS command paths
  2. ; Used in ShellScr by Kyzer/CSG
  3. ;
  4. ; Based on dospath.library source by Stefan Becker
  5. ; all functions withstand being passed NIL
  6.  
  7. call    macro
  8.     move.l    \2base(a4),a6
  9.     movem.l    a0/a1/d1,-(sp)
  10.     jsr    _LVO\1(a6)
  11.     movem.l    (sp)+,d1/a0/a1
  12.     endm
  13. clra    macro
  14.     suba.l    \1,\1
  15.     endm
  16. baddr    macro
  17.     add.l    \1,\1
  18.     add.l    \1,\1
  19.     endm
  20. mkbaddr    macro
  21.     asr.l    #2,\1
  22.     endm
  23.  
  24.     include    dos/dos.i
  25.     include    dos/dosextens.i
  26.     include    exec/memory.i
  27.     include    exec/nodes.i
  28.     include    exec/ports.i
  29.     include    exec/tasks.i
  30.     include    exec/types.i
  31.     include    lvo/dos_lib.i
  32.     include    lvo/exec_lib.i
  33.     include    workbench/startup.i
  34.  
  35.     include    eglobs.i
  36.  
  37.      STRUCTURE    PathList,0
  38.     BPTR    pl_next
  39.     BPTR    pl_lock
  40.     LABEL    pl_SIZEOF
  41.  
  42. ;------------------------------------------------------------------------------
  43. ; PTR TO commandlineinterface=getcli(PTR TO process) - private call
  44. ; d0=0 and Z flag set if not a process or no commandlineinterface
  45.  
  46. getcli    moveq    #0,d0
  47.     cmp.l    d0,a0
  48.     beq.s    .exit
  49.     cmp.b    #NT_PROCESS,LN_TYPE(a0)
  50.     bne.s    .exit
  51.     move.l    pr_CLI(a0),d0
  52.     baddr    d0
  53. .exit    rts
  54.  
  55. ;------------------------------------------------------------------------------
  56. ; PTR TO pathlist=getpathlist(PTR TO process)
  57. ; returns a normal pointer to the initial pathlist entry of the process
  58.  
  59.     xdef    getpathlist_i
  60. getpathlist_i
  61.     move.l    4(sp),a0
  62. getpathlist
  63.     bsr.s    getcli
  64.     beq.s    .fail
  65.     move.l    d0,a0
  66.     move.l    cli_CommandDir(a0),d0
  67.     baddr    d0
  68. .fail    rts
  69.  
  70.  
  71. ;------------------------------------------------------------------------------
  72. ; BPTR TO pathlist=getpath()
  73. ; makes a clone of 'your' pathlist. NOTE: returns BPTR, not PTR
  74.  
  75.     xdef    getpath
  76. getpath    move.l    execbase(a4),a6
  77.     jsr    _LVOForbid(a6)
  78.     move.l    wbmessage(a4),d0    ; from eglobs.i
  79.     beq.s    .getslf
  80.     move.l    d0,a0
  81.     bsr.s    getwbtask
  82.     bra.s    .gottsk
  83. .getslf    suba.l    a1,a1
  84.     jsr    _LVOFindTask(a6)
  85. .gottsk    move.l    d0,a0
  86.     bsr.s    getpathlist
  87.     move.l    d0,a0
  88.     bsr.s    copypathlist
  89.     move.l    d0,-(sp)
  90.     move.l    execbase(a4),a6
  91.     jsr    _LVOPermit(a6)
  92.     move.l    (sp)+,d0
  93.     mkbaddr    d0
  94.     rts
  95.  
  96. ;------------------------------------------------------------------------------
  97. ; PTR TO process=getwbtask(PTR TO wbstartup)
  98. ; returns a pointer to the Workbench/Launcher's process
  99.  
  100.     xdef    getwbtask_i
  101. getwbtask_i
  102.     move.l    4(sp),a0
  103. getwbtask
  104.     move.l    MN_REPLYPORT(a0),d0
  105.     bne.s    .port
  106.     lea    .wbname(pc),a1
  107.     move.l    execbase(a4),a6
  108.     jmp    _LVOFindTask(a6)
  109. .port    move.l    d0,a0
  110.     move.l    MP_SIGTASK(a0),d0
  111.     rts
  112. .wbname    dc.b    'Workbench',0
  113.     even
  114.  
  115. ;------------------------------------------------------------------------------
  116. ; PTR TO pathlist=copypathlist(PTR TO pathlist)
  117. ; clone a pathlist
  118.  
  119. FROM    equr    A0
  120. CURRENT    equr    A1
  121. HEAD    equr    A2
  122. NEXT    equr    A3    ;
  123. ZERO    equr    D7    ; constant 0
  124.  
  125. tsta    macro
  126.     cmp.l    ZERO,\1
  127.     endm
  128.  
  129.     xdef    copypathlist_i
  130. copypathlist_i
  131.     move.l    4(sp),FROM
  132. copypathlist
  133.     movem.l    d7/a2/a3,-(sp)
  134.     clra    CURRENT
  135.     clra    HEAD
  136.     clra    NEXT
  137.     moveq    #0,d7
  138.  
  139. .again
  140.     tsta    FROM
  141.     beq.s    .end
  142.  
  143.     tsta    NEXT
  144.     bne.s    .gotmem
  145.  
  146.     moveq    #pl_SIZEOF,d0
  147.     moveq    #MEMF_PUBLIC,d1
  148.     call    AllocVec,exec
  149.     move.l    d0,NEXT    ; if (!NEXT) NEXT=AllocVec(sizeof(PathList), MEMF_PUBLIC)
  150.     
  151. .gotmem    tsta    NEXT    ; if (!NEXT) { freepathlist(HEAD); return NULL; }
  152.     bne.s    .got
  153.     move.l    HEAD,a0
  154.     bsr.s    freepathlist
  155.     moveq    #0,d0
  156.     rts
  157. .got
  158.     move.l    pl_lock(FROM),d1
  159.     call    DupLock,dos
  160.     move.l    d0,pl_lock(NEXT)
  161.     beq.s    .next
  162.     clr.l    pl_next(NEXT)
  163.  
  164.     tsta    HEAD
  165.     bne.s    .gothd
  166.     move.l    NEXT,HEAD    ; if (!HEAD) HEAD=NEXT
  167. .gothd
  168.  
  169.     tsta    CURRENT
  170.     beq.s    .nonext
  171.     move.l    NEXT,d0
  172.     mkbaddr    d0
  173.     move.l    d0,pl_next(CURRENT)
  174. .nonext    move.l    NEXT,CURRENT
  175.     clra    NEXT
  176.  
  177. .next    move.l    pl_next(FROM),FROM    ; FROM=BADDR(FROM.next)
  178.     baddr    FROM
  179.     bra.s    .again
  180.  
  181. .end    tsta    NEXT
  182.     beq.s    1$
  183.     move.l    NEXT,a1
  184.     call    FreeVec,exec    ; if (!NEXT) FreeVec(NEXT)
  185. 1$
  186.  
  187.     move.l    HEAD,d0        ; return HEAD
  188. .done    movem.l    (sp)+,d7/a2/a3
  189.     rts
  190.  
  191. ;------------------------------------------------------------------------------
  192. ; freepathlist(PTR TO pathlist)
  193. ; frees a pathlist - note it takes a normal pointer, not a BPTR
  194.  
  195.     xdef    freepathlist_i
  196. freepathlist_i
  197.     move.l    4(sp),a0
  198. freepathlist
  199. .again    move.l    a0,a1        ; current(a1) = next(a0)
  200.     moveq    #0,d0
  201.     cmp.l    d0,a1        ; end if current=0
  202.     beq.s    .done
  203.     move.l    pl_next(a1),a0    ; next=BADDR(current.next)
  204.     baddr    a0
  205.  
  206.     move.l    pl_lock(a1),d1
  207.     call    UnLock,dos    ; d1=current.lock
  208.     call    FreeVec,exec    ; a1=current
  209.  
  210.     bra.s    .again
  211. .done    rts
  212.  
  213. ;------------------------------------------------------------------------------
  214. ; PTR TO pathlist=setpathlist(PTR TO process,PTR TO pathlist)
  215. ; if a process, it will get it's pathlist set and return it's old process
  216.  
  217. setpathlist_ii
  218.     move.l    8(sp),a0
  219.     move.l    4(sp),a1
  220. setpathlist
  221.     bsr    getcli
  222.     beq.s    .done    ; return 0 if not a process in a0
  223.     move.l    d0,a0
  224.     move.l    cli_CommandDir(a0),d0    ; hold old pathlist
  225.     move.l    a1,d1
  226.     beq.s    .fail            ; ignore install if no newlist
  227.     mkbaddr    d1            ; MKBADDR(newlist)
  228.     move.l    d1,cli_CommandDir(a0)    ; install new list
  229. .fail    baddr    d0            ; return BADDR(oldlist)
  230. .done    rts
  231.